var i=1;
var name = "Any Object";
var ids = name.replace(/\s/g,"");
var count = 5;
var desktop = document.getElementById("desktop").contentWindow.document;
var breadCrumb = desktop.getElementById("breadcrum").contentWindow.document;
var widgetmodeler = breadCrumb.getElementById("widgetmodeler").contentWindow;
function generateClick(documentObj, eventType, srcElmt) {
	var eventObject = document.createEvent("Event");
	eventObject.initEvent(eventType, true, false);
	srcElmt.dispatchEvent(eventObject);
}
function getCordysRoot(){
	return desktop.getElementById("ufo_dialog_CordysRoot").contentWindow.document;
}

(function recursive(){
	widgetmodeler.showModeler("tabApplicationObject");
	var thisObj = widgetmodeler.document.getElementById("newappobjectmenu");
	widgetmodeler.onSubMenuClick(thisObj);
	generateClick(widgetmodeler.document, "click", thisObj);
	setTimeout(function() {
		newObjDialog = getCordysRoot();
		newObjDialog.getElementById("objectName").value = name+i;
		newObjDialog.getElementById("objectID").value = ids+i;
		okButton = newObjDialog.getElementById("okButton");
		generateClick(newObjDialog, "click", okButton);
		setTimeout(function(){
			frameTags = widgetmodeler.document.getElementsByTagName("iframe");
			appObjModeler = frameTags[frameTags.length-1].contentWindow.document;
			newButton = appObjModeler.getElementById("newButton");
			generateClick(appObjModeler, "click", appObjModeler.getElementById("newButton"));
			setTimeout(function(){
				newObjDialog = getCordysRoot();
				newObjDialog.getElementById("inputLabelName").value = name + "primary key";
				newObjDialog.getElementById("lblFieldId").value = ids+"PrimaryKey";					
				newObjDialog.getElementById("chkIdentifyingField").checked = "true";
				newObjDialog.getElementById("chkRequiredField").checked = "true";
				generateClick(newObjDialog, "click", newObjDialog.getElementById("btnDone"));
				setTimeout(function(){
					checkInButton = appObjModeler.getElementById("btnSubmit");
					generateClick(appObjModeler, "click", checkInButton);
					setTimeout(function(){
						newObjDialog = getCordysRoot();
						generateClick(newObjDialog, "click", newObjDialog.getElementById("btnOk"));
						if(i++<count)
							setTimeout(recursive, 3000);
						},2000);
					},1000);
				},3000);
			},3500);
	},3000);
})();
